using System.Reflection;

namespace Aurora.TaskScheduler.Abstractions.BaseModel;

/// <summary>
/// task scheduler 参数
/// </summary>
public class TaskSchedulerOptions
{
    /// <summary>
    /// 扩展的参数服务
    /// </summary>
    public IList<ITaskScheduleOptionsExtension> Extensions { get; }

    /// <summary>
    /// 默认的 group name 默认为 DEFAULT
    /// </summary>
    public string DefaultGroupName { get; set; }

    /// <summary>
    /// 扫描的程序集
    /// </summary>
    public List<Assembly> Assemblies { get; set; }

    /// <summary>
    /// 数据保留时间（单位天） -1 代表一直保留 默认值 -1
    /// </summary>
    public int RetentionTime { get; set; } = -1;

    /// <summary>
    /// 是否使用任务锁
    /// </summary>
    public bool UseTaskLock { get; set; } = false;

    public TaskSchedulerOptions()
    {
        Extensions = new List<ITaskScheduleOptionsExtension>();
        Assemblies = new List<Assembly>();
        DefaultGroupName = "DEFAULT";
    }


    public string GetGroupName()
    {
        return string.IsNullOrWhiteSpace(DefaultGroupName) ? "DEFAULT" : DefaultGroupName;
    }

    /// <summary>
    /// Registers an extension that will be executed when building services.
    /// </summary>
    /// <param name="extension"></param>
    public void RegisterExtension(ITaskScheduleOptionsExtension extension)
    {
        if (extension == null) throw new ArgumentNullException(nameof(extension));

        Extensions.Add(extension);
    }
}